package tedu.boot26.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import tedu.boot26.entity.Hero;
import tedu.boot26.mapper.HeroMapper;

import java.util.List;

@Controller
public class HeroController {
    @Autowired
    HeroMapper mapper;

    @RequestMapping("/add")
    @ResponseBody
    public String add(Hero hero){
        System.out.println("hero = " + hero);
        mapper.insert(hero);
        return "添加成功!!!";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public String delete(String name){
        System.out.println("name = " + name);
        mapper.delete(name);
        return "删除成功!!!";
    }

    @RequestMapping("/update")
    @ResponseBody
    public String update(Hero hero){
        System.out.println("hero = " + hero);
        mapper.updateById(hero);
        return "修改成功!!!";
    }

    @RequestMapping("/select")
    @ResponseBody
    public String select(){
        List<Hero> heroList = mapper.selectHero();
        return heroList.toString();
    }
}
